package gagak.framework.web.paramresovler.converter;

import gagak.framework.web.exception.HttpMessageNotReadableException;
import gagak.framework.web.exception.HttpMessageNotWritableException;
import gagak.framework.web.paramresovler.requestbody.HttpInputMessage;
import gagak.framework.web.paramresovler.requestbody.HttpMessageConverter;
import gagak.framework.web.paramresovler.requestbody.HttpOutputMessage;
import gagak.framework.web.support.http.MediaType;

import java.io.IOException;
import java.lang.reflect.Type;

/*
 * @program: ce
 * @description:  通用HttpMessager转换器
 * @author: houhong
 * @create: 2022-11-30 20:34
 */
public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T> {


    /*
    *  判断是否可以读
    */
    boolean canRead(Type type, Class<?> contextClass, MediaType mediaType);

    /*
    * 这里将requestbody的数据写成范型T
    */
    T read(Type type, Class<?> contextClass, HttpInputMessage inputMessage)
            throws IOException, HttpMessageNotReadableException;




    boolean canWrite(Type type, Class<?> clazz, MediaType mediaType);


    void write(T t, Type type, MediaType contentType, HttpOutputMessage outputMessage)
            throws IOException, HttpMessageNotWritableException;
}